<template>
  <div>
    <elm-page-tb>
      <template #top>
        <el-input placeholder="请查询输入内容" size="mini" prefix-icon='el-icon-search' style="width:250px;" v-model="postData.name" clearable></el-input>
        <right>
          <el-button-group>
            <el-button icon="el-icon-search" size="mini" @click="tablebinding()">查询</el-button>
            <elm-open-button url="product_edit" title="新增"  width="900" height="85%">新增</elm-open-button>
          </el-button-group>
        </right>
      </template>
      <elm-table url="/business/plm/product/GetData" :post-data="postData" :page-size="10" height="100%">
        <el-table-column prop="sys_code_key" label="产品编码" align="center" width="120"></el-table-column>
        <el-table-column prop="name" label="名称" align="center"></el-table-column>
        <el-table-column prop="model" label="型号" align="center"></el-table-column>
        <el-table-column prop="specification" label="规格" align="center"></el-table-column>
        <el-table-column prop="unit" label="单位" align="center"></el-table-column>
        <el-table-column prop="category_mc" label="产品类型" align="center"></el-table-column>
        <el-table-column prop="attribute" label="产品属性" align="center"></el-table-column>
        <el-table-column prop="role" label="产品角色" align="center"></el-table-column>
        <el-table-column prop="loss_rate" label="损耗率" align="center">
          <template v-slot="scope">
            {{scope.row.loss_rate?scope.row.loss_rate+"%":""}}
          </template>
        </el-table-column>
        <el-table-column prop="pricing_method" label="计价方式" align="center" width="120"></el-table-column>
        <el-table-column prop="status" label="状态" align="center"></el-table-column>
        <el-table-column prop="description" label="产品说明" align="center"></el-table-column>
        <el-table-column prop="parameters" label="产品参数" align="center"></el-table-column>
        <el-table-column prop="created_date" label="创建日期" align="center" width="100" :formatter="formatDate"></el-table-column>
        <el-table-column prop="remark" label="备注" align="center"></el-table-column>
        <el-table-column fixed="right" label="工序" width="80px" align="center">
          <template v-slot="scope">
            <elm-open-button url="craft" title="工序编辑" width="900" height="85%" :data="{ pd_code: scope.row.sys_code_key }" type="text">工序编辑</elm-open-button>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120px" align="center">
          <template v-slot="scope">
            <elm-open-button url="product_edit" title="编辑"   width="900" height="85%" :data="{ model: scope.row }" type="text">编辑</elm-open-button>
            <el-button type="text" size="mini" @click="deleteData(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </elm-table>
    </elm-page-tb>
  </div>
</template>

<script>
export default {
  extends: elmVueBase,
  data() {
    return {
      postData: { name: null}
    }
  },
  created() {
  },
  methods: {
    async deleteData(data) {
      await this.delete('/business/plm/product/Delete', { id: data.id });
      let res=await elm.post("/business/plm/product/craft/GetData",{pd_code:data.sys_code_key});
      for(let i=0;i<res.length;i++)
        await elm.post("/business/plm/product/craft/Delete",res[i]);
      this.tablebinding();
    },
  }
}
</script>
